We affirm that we are the authors of this project and while completing it, we have followed St.Clair’s college’s policies on academic integrity.
R version used- R version 4.2.1 (2022-06-23 ucrt)
RStudio used- 2022.07.1 version
List of R packages used- tidyverse, here, plotly, ggplot2.
library("tidyverse")
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library("here")
## here() starts at C:/F Drive/BAsic stats DAB 501/R programs
library("plotly")
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library("ggplot2")
indian_df <- read.csv("C:/F Drive/BAsic stats DAB 501/R programs/Indian_Election_2019.csv")
ggplot(data = indian_df,mapping = aes(POSTAL.VOTES))+
geom_histogram(binwidth = 250,color="black",fill="yellow")+
labs(title ="TOTAL NUMBER OF POSTAL VOTES",caption = "Data Source: Indian Election 2019",x = "Number of Postal Votes",y = "Number of Votes")+
theme(plot.title = element_text(color="blue", size=12, face="bold"),
plot.caption = element_text(colour="red",size= 8,face = "bold",hjust = 1))
indian_df <- indian_df %>% mutate(GENERAL.VOTES=GENERAL.VOTES/10000)
indian_df <- indian_df %>% mutate(TOTAL.VOTES = TOTAL.VOTES/10000)
indian_df <- indian_df %>% mutate(TOTAL.ELECTORS=TOTAL.ELECTORS/10000)
party_df <- indian_df %>% filter(PARTY %in% c("BJP","INC","AAP","SP","TDP","SAP", "MNM","CPI(ML)(L)","AIADMK","SAD(M)","DMDK","SAD","NOTA"))
num_data <- transform(party_df,CRIMINAL.CASES = as.numeric(CRIMINAL.CASES))
## Warning in eval(substitute(list(...)), `_data`, parent.frame()): NAs introduced
## by coercion
tvotes_density <- ggplot(data = indian_df,mapping = aes(TOTAL.VOTES))+
geom_histogram(aes(y = ..density..),binwidth=10,color="red",fill="blue")+
geom_density(color = "#000000", fill = "#F85700", alpha = 0.6) +
#ggtitle("DENSITY ACCORDING TO TOTAL VOTES ") +
labs(x = "Total Votes in Ten Thousand", y = "Density",caption = "Data Source:Indian Election 2019",title = "DENSITY ACCORDING TO TOTAL VOTES ")+
theme(plot.title = element_text(color="blue", size=12, face="bold"))
ggplotly(tvotes_density)
#lab_gender <- c("Male", "Female", "Others")
ggplot(indian_df,mapping = aes(x = GENDER))+
scale_x_discrete(breaks = c("MALE", "FEMALE", ""),
labels = c("Male", "Female", "Others"))+
geom_bar(color="red",fill="yellow")+
geom_text(aes(label = ..count..), stat = "count",
position = position_stack(vjust=0.5))+
labs(x = "Gender", y = "Count",caption = "Data Source:Indian Election 2019",title = "GENDER WISE COUNT PARTICIPATING IN INDIAN ELECTION 2019")+
theme(plot.title = element_text(color="blue", size=12, face="bold"),
plot.caption = element_text(colour="red",size= 8,face = "bold",hjust = 1))
# 2 Question Plot-2
ggplot(indian_df,mapping=aes(x = CATEGORY))+
scale_x_discrete(breaks = c("ST", "", "SC","GENERAL"),
labels = c("ST", "Others", "SC","General"))+
geom_bar(color="black",fill = "cyan")+
coord_flip()+
geom_text(aes(label = ..count..), stat = "count",
position = position_stack(vjust=0.5))+
labs(x = "Category", y = "Count",title = "No. of Candidates according to Category",caption = "Data Source:Indian Election 2019")+
theme(plot.title = element_text(color="blue", size=12, face="bold"),
plot.caption = element_text(colour="red",size= 8,face = "bold",hjust = 1))
# 3 Question
party_crime <- ggplot(num_data,aes(PARTY,CRIMINAL.CASES))+
geom_boxplot(aes(fill= PARTY), outlier.stroke = 2, color="black", outlier.shape=16,outlier.size=1, notch=FALSE) +
labs(title = "CRIMINAL CASES OF A PARTICULAR PARTY", x = "Party Name", y = "Criminal Cases",caption = "Data Source:Indian Election 2019")+
theme(plot.title = element_text(color="blue", size=12, face="bold"),
plot.caption = element_text(colour="red",size= 8,face = "bold",hjust = 1))
party_crime
## Warning: Removed 248 rows containing non-finite values (stat_boxplot).
symb_party <- ggplot(party_df, aes(y=PARTY,x= SYMBOL))+
geom_point(color="red")+
labs(title="SCATTER PLOT SHOWING DETAILS OF PARTY WITH THEIR SYMBOLS",
caption = "Data Source: Indian Election 2019", y = "Party Name" , x = "Different Party Symbols")+
theme(plot.title = element_text(color="blue", size=12, face="bold"))
ggplotly(symb_party)
electrol_state <- ggplot(indian_df, aes(y = STATE, x = TOTAL.ELECTORS))+
geom_bar(stat="identity", width = 0.9, fill="pink") +
labs(title="TOTAL ELECTORS IN A PARTICULAR STATE", y = "States", x = "Total Electors in Ten Thousand") +
theme(plot.title = element_text(color="blue", size=12, face="bold"))
ggplotly(electrol_state)
ggplot(party_df, aes(x=WINNER, y=PARTY, fill=GENDER))+
geom_bar(stat = "identity")+
facet_wrap(~CATEGORY,nrow = 2)+
labs(title="Displaying info of Winners and Party Name according to Gender",
caption = "Data Source: Indian Election 2019", x = "Winners", y = "Party Names")+
theme(plot.title = element_text(color="blue", size=12, face="bold"),
plot.caption = element_text(colour="red",size= 8,face = "bold",hjust = 1))
point <- ggplot(party_df,mapping = aes(y=PARTY,x=STATE))+
geom_point(aes(color=WINNER))+
theme(axis.text.x = element_text(angle=75, vjust=0.6),axis.text.y = element_text(angle=-75, vjust=0.4)) +
labs(title = "WINNING CANDIDATES FROM PARTICULAR PARTY AND STATE", x = "State Name", y = "Party Name")+
theme(plot.title = element_text(color="blue", size=12, face="bold"))
ggplotly(point)